package com.ruoyi.web.controller.system;


import com.ruoyi.common.core.page.ResponseResult;
import com.ruoyi.common.enums.ChannelEnum;
import com.ruoyi.system.biz.UserRateBizService;
import com.ruoyi.system.domain.Cash;
import com.ruoyi.system.domain.UserRate;
import com.ruoyi.system.service.CashHistoryService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.UserRateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "管理后台:用户费率接口")
@RestController
@RequestMapping("/admin/userRate")
public class AdminUserRateController extends AdminController {
    @Resource
    private UserRateService userChannelService;

    @Resource
    private UserRateBizService userRateBizService;
    @Resource
    private ISysUserService userService;

    @Resource
    private CashHistoryService cashHistoryService;

    @ApiOperation(value = "将用户的费率调整")
    @GetMapping("clean")
    public ResponseResult clean() {
        this.checkAdmin();
        userRateBizService.clean();

        return this.setSuccessResult();
    }


    @ApiOperation(value = "用户通道列表")
    @GetMapping("list")
    public ResponseResult<List<Cash>> list(UserRate userChannel) {
        this.checkAdmin();
        this.startPage();
        List<UserRate> list = userChannelService.findList(userChannel);
        return this.setSuccessResult(this.getPageResult(list));
    }


    @ApiOperation(value = "详情")
    @GetMapping("getById")
    public ResponseResult get(Long id) {
        this.checkAdmin();
        UserRate zfbConfig = userChannelService.getById(id);

        return this.setSuccessResult(zfbConfig);
    }

    @ApiOperation(value = "删除")
    @GetMapping("delById")
    public ResponseResult delById(Long id) {
        this.checkAdmin();
        userChannelService.delById(id);
        return this.setSuccessResult();
    }

    @ApiOperation(value = "新增")
    @PostMapping("save")
    public ResponseResult save(@RequestBody UserRate userChannel) {
        this.checkAdmin();
        //  SysUser sysUser = userService.check(userChannel.getUserId());

        userChannel.setChannelName(ChannelEnum.getName(userChannel.getChannelCode()));
        if (userChannel.getId() != null) {
            userChannelService.updateDomain(userChannel);

        } else {
            userChannelService.addDomain(userChannel);
        }

        return this.setSuccessResult();
    }

}
